Current File : //usr/lib/python3/dist-packages/twisted/spread/test/__pycache__/test_jelly.cpython-312.pyc
�

Ϫ�fmJ���dZddlZddlZddlmZddlmZmZmZddl	m
Z
ddlmZGd�dej�ZGd	�d
�Zd�ZGd�d
�ZGd�d�ZGd�d�ZGd�d�ZGd�d�Zd�ZGd�de�ZGd�de�ZGd�dej2ej4�ZGd�dej2ej4�ZGd�d e�Zy)!z/
Test cases for L{jelly} object serialization.
�N)�StringTransport)�banana�jelly�pb)�unittest)�TestCasec��eZdZdZdZdd�Zy)�TestNodezD
    An object to test jellyfying of new style class instances.
    �Nc��|r0|jdz|_|jj|�nd|_||_g|_y)N�)�id�children�append�parent)�selfrs  �@/usr/lib/python3/dist-packages/twisted/spread/test/test_jelly.py�__init__zTestNode.__init__s;����i�i�!�m�D�G��O�O�"�"�4�(��D�G������
��N)�__name__�
__module__�__qualname__�__doc__�	classAttrr�rrr
r
s����I�rr
c��eZdZdZd�Zy)�A�
    Dummy class.
    c��y�z;
        Method to be used in serialization tests.
        Nr�rs r�amethodz	A.amethod(��rN)rrrrr#rrrrr#����rrc��y)z:
    A dummy function to test function serialization.
    Nrr"s r�afuncr'.r$rc��eZdZdZd�Zy)�Brc��yr!rr"s r�bmethodz	B.bmethod9r$rN)rrrrr+rrrr)r)4r%rr)c��eZdZdZd�Zy)�Crc��yr!rr"s r�cmethodz	C.cmethodDr$rN)rrrrr/rrrr-r-?r%rr-c��eZdZdZy)�Dz 
    Dummy new-style class.
    N)rrrrrrrr1r1Js��rr1c�(�eZdZdZdZdd�Zd�Zd�Zy)�Ez+
    Dummy new-style class with slots.
    ��x�yNc� �||_||_yrr4�rr5r6s   rrz
E.__init__W��������rc�4�|j|jd�S)Nr4r4r"s r�__getstate__zE.__getstate__[s���V�V�$�&�&�)�)rc�,�|d|_|d|_y)Nr5r6r4�r�states  r�__setstate__zE.__setstate__^s���s�����s���r)NN)rrrr�	__slots__rr;r?rrrr3r3Ps����I��*�rr3c��eZdZd�Zd�Zy)�SimpleJellyTestc� �||_||_yrr4r8s   rrzSimpleJellyTest.__init__dr9rc�4�|j|jk(Sr)�__dict__�r�others  r�isTheSameAszSimpleJellyTest.isTheSameAshs���}�}����.�.rN)rrrrrHrrrrBrBcs���/rrBc���tj|�}tj|�}tj|�}tj|�}|j||�y)zt
    Verify that the given object round-trips through jelly & banana and comes
    out equivalent to the input.
    N)rr�encode�decode�unjelly�assertEqual)�testCase�toSerialize�jellied�encoded�decoded�	unjellieds      r�jellyRoundTriprTlsL��
�k�k�+�&�G��m�m�G�$�G��m�m�G�$�G��
�
�g�&�I�����i�0rc���eZdZdZdgd�gd�gd�gd�gZd�Zd�Zd	�Zd
�Zd�Z	d�Z
d
�Zd�Zd�Z
d�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd �Zd!�Zd"�Z d#�Z!d$�Z"y%)&�
JellyTestsz�
    Testcases for L{jelly} module serialization.

    @cvar decimalData: serialized version of decimal data, to be used in tests.
    @type decimalData: L{list}
    slist)�decimali����)rWrr)rW�@�r)rWi������c�8�tj|�}tj�}|j�tj||�|jj|�|j
tjtj||�y)z�
        Helper test method to test security options for a type.

        @param inputList: a sample input for the type.
        @type inputList: L{list}

        @param atom: atom identifier for the type.
        @type atom: L{str}
        N)r�SecurityOptions�allowBasicTypesrL�allowedTypes�pop�assertRaises�
InsecureJelly)r�	inputList�atom�c�tasters     r�
_testSecurityzJellyTests._testSecurity�sl��
�K�K�	�"���&�&�(����� �
�
�
�a�� �������%����%�-�-�u�}�}�a��Hrc�D�t�}t�}t�}|j|_||_tj}t`	|j
ttjtj|��|t_y#|t_wxYw)z�
        If a class change after an instance has been created, L{jelly.unjelly}
        shoud raise a C{TypeError} when trying to unjelly the instance.
        N)
rr)r-r/r+�ar`�	TypeErrorrrL)rrh�brd�savecmethods     r�test_methodsNotSelfIdentityz&JellyTests.test_methodsNotSelfIdentity�sk��

�C��
�C��
�C���I�I��	�����i�i��
�I�	$����i�������A��G�#�A�I���A�I�s�8B�
Bc�Z�t�}d|_t�}||_||_t	j|�}t	j
|�}|j
|t�|j|j|j�|j|jd�y)z�
        Test that a new style class can be jellied and unjellied with its
        objects and attribute values preserved.
        r
N)	r1r5�n2�n3rrL�assertIsInstance�assertIsrM)r�nrnrd�ms     r�
test_newStylezJellyTests.test_newStyle�s|��

�C�����
�S���������K�K��N���M�M�!������a��#��
�
�a�d�d�A�D�D�!�������a� rc���t�}d|_tj|�}tj|�}|j	|t�|j|jd�y)z�
        A class defined with I{slots} can be jellied and unjellied with the
        values for its attributes preserved.
        r
N)r3r5rrLrprM)rrrrdrss    r�test_newStyleWithSlotsz!JellyTests.test_newStyleWithSlots�sQ��

�C������K�K��N���M�M�!������a��#�������a� rc��tg}tjtj|��}|j||�y)zm
        Test that a new style class type can be jellied and unjellied
        to the original type.
        N)r1rrLrM�r�t�rs   r�test_typeNewStylezJellyTests.test_typeNewStyle�s1��
�C���M�M�%�+�+�a�.�)������A�rc��tg}tjtj|��}|j||�y)ze
        Test that a builtin type can be jellied and unjellied to the original
        type.
        N)�strrrLrMrxs   r�test_typeBuiltinzJellyTests.test_typeBuiltin�s1��
�E���M�M�%�+�+�a�.�)������A�rc�&�tjj�}tjj�|z
}||g}tj|�}tj|�}|j	||�|j||�y)z�
        Jellying L{datetime.timedelta} instances and then unjellying the result
        should produce objects which represent the values of the original
        inputs.
        N)�datetime�nowrrLrM�assertIsNot)r�dtn�dtdrbrd�outputs      r�
test_dateTimezJellyTests.test_dateTime�sv�����#�#�%�����#�#�%��+���#�J�	��K�K�	�"�����q�!������F�+�����F�+rc�6�tjddd�}tjdddd�}tjj||�}|tjddd�z
}t	||�t	||�t	||�t	||�y	)
z�
        Jellying L{datetime.time}, L{datetime.timedelta}, L{datetime.datetime},
        and L{datetime.date} objects should result in jellied objects which can
        be serialized and unserialized with banana.
        i���r
��iX�N)r��date�time�combinerT)r�
sampleDate�
sampleTime�sampleDateTime�sampleTimeDeltas     r�test_bananaTimeTypeszJellyTests.test_bananaTimeTypes�s����]�]�4��B�/�
��]�]�1�b�!�S�1�
�!�*�*�2�2�:�z�J��(�8�+<�+<�T�1�a�+H�H���t�Z�(��t�Z�(��t�^�,��t�_�-rc�D�tjd�tjd�tjd�tjd�g}tj|�}tj|�}|j	||�|j||�y)z�
        Jellying L{decimal.Decimal} instances and then unjellying the result
        should produce objects which represent the values of the original
        inputs.
        �9.95rrY�-78.901N)�decimal�DecimalrrLrMr�)rrbrdr�s    r�test_decimalzJellyTests.test_decimal�sy��
�O�O�F�#��O�O�A���O�O�F�#��O�O�I�&�	
�	�
�K�K�	�"�����q�!������F�+�����F�+rc�
�tjd�tjd�tjd�tjd�g}tj|j�}|j||�y)a
        Unjellying the s-expressions produced by jelly for L{decimal.Decimal}
        instances should result in L{decimal.Decimal} instances with the values
        represented by the s-expressions.

        This test also verifies that L{decimalData} contains valid jellied
        data.  This is important since L{test_decimalMissing} re-uses
        L{decimalData} and is expected to be unable to produce
        L{decimal.Decimal} instances even though the s-expression correctly
        represents a list of them.
        r�rrYr�N)r�r�rrL�decimalDatarM)r�expectedr�s   r�test_decimalUnjellyzJellyTests.test_decimalUnjellysa��
�O�O�F�#��O�O�A���O�O�F�#��O�O�I�&�	
�����t�/�/�0�������*rc�T�tjd�g}|j|d�y)z�
        By default, C{decimal} objects should be allowed by
        L{jelly.SecurityOptions}. If not allowed, L{jelly.unjelly} should raise
        L{jelly.InsecureJelly} when trying to unjelly it.
        r�rWN)r�r�rf�rrbs  r�test_decimalSecurityzJellyTests.test_decimalSecuritys%���_�_�V�,�-�	����9�j�1rc��hd�g}tjtj|��}|j||�|j||�y)z�
        Jellying C{set} instances and then unjellying the result
        should produce objects which represent the values of the original
        inputs.
        �r
�r�N)rrLrMr��rrbr�s   r�test_setzJellyTests.test_set&sB���K�	����u�{�{�9�5�6������F�+�����F�+rc��tgd��g}tjtj|��}|j||�|j	||�y)z�
        Jellying L{frozenset} instances and then unjellying the result
        should produce objects which represent the values of the original
        inputs.
        �r
r�r�N)�	frozensetrrLrMr�r�s   r�test_frozensetzJellyTests.test_frozenset1sH���y�)�*�	����u�{�{�9�5�6������F�+�����F�+rc�2�hd�g}|j|d�y)z�
        By default, C{set} objects should be allowed by
        L{jelly.SecurityOptions}. If not allowed, L{jelly.unjelly} should raise
        L{jelly.InsecureJelly} when trying to unjelly it.
        r�ssetN)rfr�s  r�test_setSecurityzJellyTests.test_setSecurity<s���K�	����9�f�-rc�D�tgd��g}|j|d�y)z�
        By default, L{frozenset} objects should be allowed by
        L{jelly.SecurityOptions}. If not allowed, L{jelly.unjelly} should raise
        L{jelly.InsecureJelly} when trying to unjelly it.
        r�s	frozensetN)r�rfr�s  r�test_frozensetSecurityz!JellyTests.test_frozensetSecurityEs!���y�)�*�	����9�l�3rc��|jtdd�jtdd���tdd�}tj|�}tj|�}|j|j|��y)z%
        Simplest test case.
        rhrjr
r�N)�
assertTruerBrHrrL)rrh�cerealrjs    r�test_simplezJellyTests.test_simpleNsj��	
����C��%�1�1�/�#�s�2K�L�	
�
�A�q�!�����Q����M�M�&�!������
�
�a�(�)rc�d�g}|}|j|�|j|�|j|d|d�|j|dd|�tj|�}tj|�}|j|d|d�|j|dd|�y)zJ
        Test to make sure that objects retain identity properly.
        rr
N)rrqrrL)rr5r6�s�zs     r�
test_identityzJellyTests.test_identityZs���
��
��	�����	������
�
�a��d�A�a�D�!��
�
�a��d�1�g�q�!��K�K��N���M�M�!����
�
�a��d�A�a�D�!��
�
�a��d�1�g�q�!rc���d}tjtj|��}|j||�|jt|�t|��y)N�blah)rrLrM�typer8s   r�test_strzJellyTests.test_strisE�����M�M�%�+�+�a�.�)������A������a��$�q�'�*rc��g}d|i|f}|j|�tj|�}tj|�}|j|dd|d�|j|ddd|�y)N�listrr
�rrrLrq)r�reref�
toplevelTupler�r�s     r�test_stressReferencesz JellyTests.test_stressReferencesosq���� �%��%�0�
�
���]�#��K�K�
�&���M�M�!����
�
�a��d�6�l�A�a�D�)��
�
�a��d�6�l�1�o�q�)rc��g}|f}|j|f�tj|�}tj|�}|j|ddd|�y�Nrr�)rrhryr�r�s     r�test_moreReferenceszJellyTests.test_moreReferencesxsP����
�D��	���!����K�K��N���M�M�!����
�
�a��d�1�g�a�j�!�$rc��tj�}tji�}|jtjtj||�y)z@
        Test for type-level security of serialization.
        N)rr\r`rarL)rre�dcts   r�test_typeSecurityzJellyTests.test_typeSecurity�s=���&�&�(���k�k�"�o�����%�-�-�u�}�}�c�6�Jrc�b�tjt�}|jt|�yr)rrLr1rq)r�ujs  r�test_newStyleClasseszJellyTests.test_newStyleClasses�s��
�]�]�1�
���
�
�a��rc���t�}tjtj|��tjtj|j��tgd�td�td�ddddttdditjg}|D]:}|j|tjtj|����<y)zA
        Test for all types currently supported in jelly
        r�r
�testg�����L4@Nrh)rrrLr#r'�boolrrM)rrh�items�is    r�test_lotsaTypeszJellyTests.test_lotsaTypes�s���
�C��
�
�
�e�k�k�!�n�%�
�
�
�e�k�k�!�)�)�,�-����Q��K���G�����
��
�!�H�
�I�I�

���	?�A����Q��
�
�e�k�k�!�n� =�>�	?rc�\�Gd�d�at�}t|�}t|�}t||f�}||||||d|i}tjtj|��d}|j	|j
dj
|j
dj
�y)Nc�$�eZdZd�Zd�Zd�Zd�Zy)�
TupleStatec��||_yr�rGrFs  rrzTupleState.__init__�s	��"��
rc��|jfSrr�r"s rr;zTupleState.__getstate__�s���
�
�}�$rc��|d|_yr�r�r=s  rr?zTupleState.__setstate__�s
��"�1�X��
rc�,�t|j�Sr)�hashrGr"s r�__hash__zTupleState.__hash__�s���D�J�J�'�'rN)rrrrr;r?r�rrrr�r��s��
#�
%�
&�
(rr��t3rr
)r�rrrLrqrG)rrh�t1�t2r��d�t3primes       r�
test_setStatezJellyTests.test_setState�s���	(�	(�
�C��
��]��
��]��
��R��
!��
��R��R��T�2�.���-�-����A��/��5���
�
�g�m�m�A�&�,�,�g�m�m�A�.>�.D�.D�Erc���tj�}|jtt�t�}t	�}t�}||_||_||_||_tj||�}tj||�}|j|jtj�tj|�}|jtjtj||�|j|j|jd�tjt|�}tj||�}|j|td|z�y)zA
        Test for class-level security of serialization.
        zIdentity mismatchzA came back: %sN)rr\�allowInstancesOfrr)r-rjrdr5rLrp�
Unpersistabler`rarq)rrerhrjrd�friendlyr5�means        r�test_classSecurityzJellyTests.test_classSecurity�s���&�&�(������1�%�
�C��
�C��
�C���������������;�;�q�&�)���M�M�(�F�+�����a�c�c�5�#6�#6�7��{�{�1�~�����%�-�-�u�}�}�d�F�K��
�
�a�c�c�1�3�3� 3�4��;�;�q�&�)���M�M�(�F�+���
�
�a��-��1�2rc�b�Gd�dtj�}tj|tj�|�}d|_tj
tj|��}|j
|jd�|j|tj�y)zr
        Test that if Unjellyable is used to deserialize a jellied object,
        state comes out right.
        c��eZdZy)�7JellyTests.test_unjellyable.<locals>.JellyableTestClassN�rrrrrr�JellyableTestClassr�����rr��valueN)r�	Jellyable�setUnjellyableForClass�Unjellyable�	attributerLrMrp)rr��inputr�s    r�test_unjellyablezJellyTests.test_unjellyable�s}��	����	�	�$�$�%7��9J�9J�K�"�$��!������u�{�{�5�1�2������)�)�7�3����f�e�&7�&7�8rc���idg}|fd�}|fd�}tdd�}tdd�}tdd�}||_||_||_tj||�	�}tj||�
�}|j|j|jj�|j
|dd�|j|j|jd
�y)Nr
c�J�|ddz|d<||d|d<t|d�S)Nr
r)r})�obj�jel�persts   r�persistentStorez:JellyTests.test_persistentStorage.<locals>.persistentStore�s3���Q�x�!�|�E�!�H�!$�E�!�H�U�1�X���u�Q�x�=� rc�(�t|�}|d|Sr�)�int)�pidstr�unjr��pids    r�persistentLoadz9JellyTests.test_persistentStorage.<locals>.persistentLoad�s���f�+�C���8�C�=� rr�r�rr��)r�)r�rzpersistentStore was not called.z$Persistent storage identity failure.)rBrjrdrrLrqr�)	rr�r�r�rhrjrdr�r5s	         r�test_persistentStoragez!JellyTests.test_persistentStorage�s����Q���,1�	!�
/4�	!�
�A�q�!���A�q�!���A�q�!������������k�k�!�_�=���M�M�#�n�=���
�
�a�c�c�1�3�3�5�5�!�����a��"C�D��
�
�a�c�c�1�3�3� F�Grc���t�}t|�}t|�t|�tj|�}tj|�}|j||�yr)r
rrL�_check_newstyle)rrr�n1r�rss     r�test_newStyleClassesAttributesz)JellyTests.test_newStyleClassesAttributessK���J��
�a�[���������k�k�!�n���M�M�#������Q��"rc��|j|j|j�|j|jd�|j|jd�|jt|j�t|j��t|j|j�D]\}}|j
||��y)Nr)rMrr�lenr�zipr)rrhrjr5r6s     rrzJellyTests._check_newstyles���������q�t�t�$�������a�(�������a�(�����Q�Z�Z��#�a�j�j�/�:���
�
�A�J�J�/�	'�D�A�q�� � ��A�&�	'rc��tj�}tj�}|jt	��tj
||��}tj�}|jt	��tj||��}|j|j|j�y)a
        A L{pb.Referenceable} instance jellies to a structure which unjellies to
        a L{pb.RemoteReference}.  The C{RemoteReference} has a I{luid} that
        matches up with the local object key in the L{pb.Broker} which sent the
        L{Referenceable}.
        ��invokerN)
r�
Referenceable�Broker�makeConnectionrrrL�assertIn�luid�localObjects)r�ref�jellyBroker�j�
unjellyBrokerr�s      r�test_referenceablezJellyTests.test_referenceables������ ���i�i�k���"�"�?�#4�5��K�K��[�1���	�	��
��$�$�_�%6�7�
�]�]�1�m�
4���
�
�b�g�g�{�7�7�8rN)#rrrrr�rfrlrtrvr{r~r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrrrrrVrVxs����	���� ��K�I�&$�"!� 
!���,�
.�,�"+�*2�	,�	,�.�4�
*�
"�+�*�%�K��?�0F�03�89� H�6	#�'�9rrVc��eZdZdZd�Zd�Zy)�JellyDeprecationTestsz+
    Tests for deprecated Jelly things
    c��tj|j|jg�}|j	t|�d�|j	|ddd�|j	|ddt�y)zD
        L{jelly.instance_atom} is deprecated since 15.0.0.
        r
r�messagezltwisted.spread.jelly.instance_atom was deprecated in Twisted 15.0.0: instance_atom is unused within Twisted.�categoryN)r�
instance_atom�
flushWarnings�test_deprecatedInstanceAtomrMr�DeprecationWarning�r�warningss  rrz1JellyDeprecationTests.test_deprecatedInstanceAtom.su��	����%�%�t�'G�'G�&H�I������X���*�����Q�K�	�"�
>�	
�
	
����!��Z�0�2D�Erc��tjdddgdgg�|j�}|jt	|�d�|j|ddd�|j|dd	t
�y
)zI
        Unjellying the instance atom is deprecated with 15.0.0.
        �instance�classz twisted.spread.test.test_jelly.A�
dictionaryr
rrztUnjelly support for the instance atom is deprecated since Twisted 15.0.0.  Upgrade peer for modern instance support.rN)rrLrrMrrrs  r�%test_deprecatedUnjellyingInstanceAtomz;JellyDeprecationTests.test_deprecatedUnjellyingInstanceAtom<s���	�
�
�
�'�#E�F���W�	
��%�%�'������X���*�����Q�K�	�"�
I�	
�
	
����!��Z�0�2D�ErN)rrrrrr%rrrrr)s���F�Frrc��eZdZd�Zy)�ClassAc�$�t|�|_yr)�ClassBrr"s rrzClassA.__init__Ns
���$�<��rN�rrrrrrrr'r'Ms�� rr'c��eZdZd�Zy)r)c��||_yr)r)rrs  rrzClassB.__init__Ss	����rNr*rrrr)r)Rs��rr)c�(�eZdZdZd�Zd�Zd�Zd�Zy)�CircularReferenceTestszN
    Tests for circular references handling in the jelly/unjelly process.
    c�*�tjtt�tjtt�tjtjt���}|j|jj|d�y)N�,Identity not preserved in circular reference)rr�r'r)rLrqr)rrhs  r�test_simpleCirclez(CircularReferenceTests.test_simpleCircle\sT��
�$�$�V�V�4�
�$�$�V�V�4��M�M�%�+�+�f�h�/�0���
�
�a�e�e�i�i��$R�Src�f�Gd�d�}|�}d|_t�}tjtt�tjtt�tj||��}tj
|�}|j
|jj|d�y)Nc��eZdZy)�HCircularReferenceTests.test_circleWithInvoker.<locals>.DummyInvokerClassNr�rrr�DummyInvokerClassr4cr�rr5r	r0)�serializingPerspectiver'rr�r)rL�failUnlessIdenticalr)rr5�dummyInvoker�a0r�a1s      r�test_circleWithInvokerz-CircularReferenceTests.test_circleWithInvokerbs���	�	�)�*��.2��+�
�X��
�$�$�V�V�4�
�$�$�V�V�4��K�K��L�1��
�]�]�1�
��� � ��F�F�J�J��J�	
rc�.�t�}t|d�}|j|�tjtj|��}|j|jt�|jt|j�|g�y)z�
        Check that a C{set} can contain a circular reference and be serialized
        and unserialized without losing the reference.
        N)	�setrB�addrrLrpr5rMr�)rr�rh�ress    rr�zCircularReferenceTests.test_setqsf��

�E���A�t�$��	���a���m�m�E�K�K��N�+�����c�e�e�S�)�����c�e�e��s�e�,rc��tdd�}t|g�}||_tjtj|��}|j|jt�|j
t|j�|g�y)z�
        Check that a L{frozenset} can contain a circular reference and be
        serialized and unserialized without losing the reference.
        N)rBr�r5rrLrprMr�)rrhr�r?s    rr�z%CircularReferenceTests.test_frozenset}sf��

�D�$�'���q�c�N������m�m�E�K�K��N�+�����c�e�e�Y�/�����c�e�e��s�e�,rN)rrrrr1r;r�r�rrrr.r.Ws���T�

�
-�
-rr.)rr�r��twisted.internet.testingr�twisted.spreadrrr�
twisted.trialr�twisted.trial.unittestrr�r
rr'r)r-r1r3rBrTrVr�Copyable�
RemoteCopyr'r)r.rrr�<module>rGs����
��4�,�,�"�+��u����"�����������&/�/�	1�n9��n9�b
!F�H�!F�H �R�[�[�"�-�-� �
�R�[�[�"�-�-��
0-�X�0-r
Page Not Found
Parece que el enlace que apuntaba aquí no sirve. ¿Quieres probar con una búsqueda?
¡Hola!